import request from '@/utils/request.js'
// import axios from 'axios'
// 获取员工列表
// 取消同一接口调用：同一接口下次调用时取消上一次的调用
/*
取消：创建一个控制器(取消方法)  1：控制器1   2：控制器2

*/
// let fn = ''
export function sysUser(data) {
  // try {
  //   fn()
  // } catch {}
  return request({
    url: '/sys/user',
    params: data
    // cancelToken: new axios.CancelToken((calcenFn) => {
    //   // calcenFn:当前请求的取消方法，只要调用，该方法就取消了
    //   fn = calcenFn
    // })
  })
}
// sysUser(page:1)   cancelFn
// sysUser(page:2) cancelFn()    cancelFn
// 新增员工
export function sysUserPost(data) {
  return request({
    url: '/sys/user',
    method: 'post',
    data
  })
}
// 删除员工
export function sysUserDel(id) {
  return request({
    url: '/sys/user/' + id,
    method: 'delete'
  })
}
// 批量新增 员工
export function sysUserBatch(data) {
  return request({
    url: '/sys/user/batch',
    method: 'post',
    data
  })
}
// 员工个人信息
export function employeesPersonalInfo(id) {
  return request({
    url: `/employees/${id}/personalInfo`
  })
}
// 员工个人信息更新
export function employeesPersonalInfoPut(data) {
  return request({
    url: `/employees/${data.userId}/personalInfo`,
    method: 'put',
    data
  })
}

// 员工岗位详情
export function employeesJobs(id) {
  return request({
    url: `/employees/${id}/jobs`
  })
}
// 员工岗位详情更新
export function employeesJobsPut(data) {
  return request({
    url: `/employees/${data.userId}/jobs`,
    method: 'put',
    data
  })
}
// 给员工分配角色
export function sysUserAssignRoles(id, roleIds) {
  return request({
    url: '/sys/user/assignRoles',
    method: 'put',
    data: {
      id,
      roleIds
    }
  })
}
